<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"/>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib prefix="frame" uri="http://www.framework.com/taglib"%>
       <div>
         <input type="hidden" name="projectId" value="${projectId}" id="projectId"/> 	 
         <input type="hidden" name="bidderId" value="${bidderId}" id="bidderId"/> 	       
       <div class="easyui-panel" data-options="border:true,title:''" style="height:150px;padding: 1px;margin-bottom: 6px">
         <table id="mydialog" class="easyui-datagrid" 
					data-options="singleSelect:false,method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
						pagination:false,multiSort:true,remoteSort:true,striped:true,height:300,
						url:'${ctx}/auctionBid/business/finance/getExscuteDeposit?projectId=${projectId}'">
					<thead>
						<tr>
							<th data-options="field:'pk',width:150,title:'单位名称',formatter:fromatterCompanyName" align="center"></th>
							<th data-options="field:'tnAmount',width:100,title:'缴纳金额',sortable:true" align="center"></th>
							<th data-options="field:'transTime',width:150,title:'缴纳时间',sortable:true" align="center"></th>
							<th data-options="field:'hstSeqNum',width:150,title:'交易流水号',sortable:true,formatter:fromatterHstSeqNum" align="center"></th>
							<th data-options="field:'bid',width:80,title:'是否投标',sortable:true,formatter:formatBid" align="center"></th>
							<th data-options="field:'returnOpt',width:80,title:'是否提交退还申请',sortable:true,formatter:formatOpt" align="center"></th>
							<th data-options="field:'status',width:140,title:'退还状态',sortable:true,formatter:formatStatus" align="center"></th>
							<th data-options="field:'addWord',width:80,title:'中间状态',sortable:true"align="center"></th>
						    <th data-options="field:'operate',width:140,title:'操作',sortable:true,formatter:formatbutton" align="center"></th>
					</tr>
					</thead>
			</table>
         </div>
         <c:if test="${showButtonFlag==true}">   
	        <tr>
	         	<td colspan="4">
			       <center><a id="submit" class="easyui-linkbutton" onclick="finishExcuteDepositReturn()">完成履约保证金操作</a></center>
			    </td> 
			</tr>
		 </c:if>      
       </div>
	    <script type="text/javascript">
	     var projectId=$("#projectId").val();        
	    // 是否投标格式化  
						function formatStatus(val, row, index) {
							if (row.status == 0) {
								return '<font color="blue">未退还</font>';
							} else if (row.status == 1) {
								return '<font color="green">已退还</font>';
							} else if (row.status == 2) {
								return '<font color="red">扣除</font>';
							}else if(row.status==-1){
								return '<font color="orange">退还失败</font>';
							}

						}

						//是否提交申请格式化	    
						function formatOpt(val, row, index) {
							if (row.returnOpt == 0) {
								return '<font color="blue">未申请</font>';
							} else if (row.returnOpt == 1) {
								return '<font color="green">申请成功</font>';
							}else if (row.returnOpt == -1){
								return '<font color="orange">申请超时</font>';
							}else if(row.returnOpt == 2){
								return '<font color="red">申请失败</font>';
							}
						}

						//是否投标    
						function formatBid(val, row, index) {
							if (row.isBid == false) {
								return '<font color="red">未投标</font>';
							} else if (row.isBid == true) {
								return '<font color="green">已投标</font>';
							}
						}

						//单位名
						function fromatterCompanyName(val, row, index) {
							if (row.pk) {
								return row.pk.companyName;
							}
						}
						
						//流水号
						function fromatterHstSeqNum(val, row, index) {
							if (row.pk) {
								return row.pk.hstSeqNum;
							}
						}
						
						   
						//操作按钮(退还按钮)
						   function formatbutton(val, row, index){
							    var returnOpt=${showButtonFlag};
					    	   if(row.status!=1 && row.status!=3 && returnOpt==true && row.status !=2){
					    		   return '<button  onclick="returnExecuteDeposit(\'' + row.pk.projectId+ '\',\'' + row.bidderId+ '\',\'' + row.pk.hstSeqNum+ '\',\'' + row.pk.companyName+ '\')" class=""><font color="green">退还</font></button>';
					    	   }else {
					    		   return '<button  onclick="" disabled="true" class=""><font color="red">退还</font></button>';	
					    	   }
					       }




						//退还履约保证金
						<%--function returnExecuteDeposit(projectId,bidderId,hstSeqNum) {--%>
							<%--top.$('#returnExecutefile').dialog({--%>
								<%--title: "退还履约保证金",--%>
								<%--iconCls: 'icon-view',--%>
								<%--width: '300',--%>
								<%--height:'200',--%>
								<%--closed: false,--%>
								<%--inline: true,--%>
								<%--cache: false,--%>
								<%--href: "${ctx}/auctionBid/business/finance/returnExecutePage=" + projectId,--%>
								<%--modal: true,--%>
								<%--buttons: [--%>
								    <%--{--%>
										<%--text: '提交',--%>
										<%--iconCls: 'icon-ok',--%>
										<%--handler: function () {--%>
                                                          <%--$.ajax({ type : 'post',--%>
														     <%--url : '${ctx}/auctionBid/business/finance/returnExecuteDeposit',--%>
															 <%--data : {--%>
																<%--projectId : projectId,--%>
																<%--projectName : null,--%>
																<%--bidderId:bidderId,--%>
																<%--hstSeqNum:hstSeqNum--%>
															<%--},--%>
																<%--success : function(data) {--%>
																	<%--if(data=="bankTimeOut"){--%>
																		 <%--top.$.messager.alert('提示信息','银行超时无响应！','error',function(){--%>
																				<%--top.$('#secondtLevelDialog').dialog('close');//关闭加载数据--%>
																				<%--$('#mydialog').datagrid('reload');--%>
																		 <%--});--%>
																	<%--}else if(data=="saveSuccess"){--%>
																		 <%--top.$.messager.alert('提示信息','退还申请成功,请等待银行处理结果！','info',function(){--%>
																				<%--top.$('#secondtLevelDialog').dialog('close');//关闭加载数据--%>
																				<%--$('#mydialog').datagrid('reload');--%>
																		 <%--});--%>
																	<%--}else if(data=="saveUnsuccess"){--%>
																		 <%--top.$.messager.alert('提示信息','退还申请失败，请确认后重新提交申请！','error',function(){--%>
																				<%--top.$('#secondtLevelDialog').dialog('close');//关闭加载数据--%>
																				<%--$('#mydialog').datagrid('reload');--%>
																		 <%--});--%>
																	<%--}else if(data=="1"){--%>
																		 <%--top.$.messager.alert('提示信息','履约保证金已经退还！','info',function(){--%>
																				<%--top.$('#secondtLevelDialog').dialog('close');//关闭加载数据--%>
																				<%--$('#mydialog').datagrid('reload');--%>
																		 <%--});--%>
																	<%--}else if(data=="2"){--%>
																		 <%--top.$.messager.alert('提示信息','履约保证金已经扣除！','error',function(){--%>
																				<%--top.$('#secondtLevelDialog').dialog('close');//关闭加载数据--%>
																				<%--$('#mydialog').datagrid('reload');--%>
																		 <%--});--%>
																	<%--}--%>
																<%--}--%>
															<%--});--%>
										                   <%--}--%>
									                   <%--},--%>
													<%--{--%>
														<%--text: '取消',--%>
														<%--iconCls: 'icon-cancel',--%>
														<%--handler: function () {--%>
														<%--top.$('#returnExecutefile').dialog('close');--%>
														<%--}--%>
													<%--}],--%>
												 <%--});--%>
												<%--top.$('#returnExecutefile').dialog("center");--%>
						                       <%--}--%>

					       		

         //等待页面
		 function loading(){
				top.$('#secondtLevelDialog').dialog({
				closable: false,
			    title:'数据加载',
			    width: '300',    
			    height: '180',    
			    closed: false,    
			    inline : true,
			    cache: false,    
			    href: "${ctx}/commons/js/loading/loading.html",
			    modal: true,
				extractor : function(data){
					if($.trim(data) == "unLogin"){
						var msn = ''||i18n[''];
						msn = msn||i18n[data];
						if(msn != undefined){
							top.$.messager.alert('提示',msn,'info',function(){top.location='${ctx}/user-login-sys-new/loginPwd';});
							return '';
						}
					}
					return data;
				}
				});
				top.$('#secondtLevelDialog').dialog("center");
			}
      
		
		
			// 完成保证金操作
			function finishExcuteDepositReturn() {
				$.ajax({type : 'post',
							url : '${ctx}/auctionBid/business/leader/getReturnList',
							data : {
								projectId : $("#projectId").val(),
								depositType:1
							},
							success : function(data) {
								if (data == "unPass") {
									$.messager.alert('提示信息','存在已提交退款申请，银行未完成退还的状态！','error');
								} else if (data == "allreturn") {
									$.messager.confirm('提示信息','是否确认履约保证金退还操作完成？',
													function(r) {
														if (r) {
															$.ajax({
																		type : 'post',
																		url : '${ctx}/auctionBid/business/leader/finishDepositReturn',
																		data : {
																			projectId : $("#projectId").val(),
																			depositType:1
																		},
																		success:function(){
																			top.$('#threeLevelDialog').dialog('close');
																			
																		},

																	});
														}
													});
								} else if (data == "unallreturn") {
									$.messager.confirm('提示信息','本项目尚存在未退还保证金，是否确认扣除这些投标人的保证金并完成保证金退还操作？',
													function(r) {
														if (r) {
															$.ajax({
																		type : 'post',
																		url : '${ctx}/auctionBid/business/leader/finishDepositReturn',
																		data : {
																			projectId : $("#projectId").val(),
																			depositType:1
																		},
																		success:function(){
																			top.$('#threeLevelDialog').dialog('close');
																			
																		},
																	});
														}
													});
								}
							}
						});

			}

         
           </script>

                 
   
  
